<script type="text/javascript">
    layui.use(['index', 'dtree'], function () {
        let dtree = layui.dtree;
        $.ajax({
            data: {
                types: '{{$station->types}}'
            },
            url: "{{route('admin.base.station.types')}}",
            success: function (data) {
                dtree.renderSelect({
                    elem: '#typeTree',
                    select: true,
                    data: data,
                    checkbar: true,
                    checkbarType: "all",
                    selectTips: '请选择',
                    method: 'GET',
                    width: "100%",
                    checkbarData: "choose",
                    checkbarFun: {
                        chooseDone: function (cheched) {
                            let types_array = [];
                            let texts_array = [];
                            cheched.forEach(function (item) {
                                types_array.push(item.nodeId);
                                texts_array.push(item.context);
                            });
                            $('#types').val(types_array.join(','));
                            $('input[dtree-id="typeTree"]').val(texts_array.join(','));
                        }
                    }
                });
                let texts_array = [];
                data.forEach(function (item) {
                    if (item.checkArr == 1) {
                        texts_array.push(item.title);
                    }
                });
                $('input[dtree-id="typeTree"]').val(texts_array.join(','));
            }
        });
    });

</script>
